package com.chenyue.cm.match.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.chenyue.cm.base.dao.LcBaseMapper;
import com.chenyue.cm.base.service.BaseServiceImpl;
import com.chenyue.cm.match.dao.JdMatchItemMapper;
import com.chenyue.cm.match.dao.JdMatchItemRelationMapper;
import com.chenyue.cm.match.domain.JdMatchItem;
import com.chenyue.cm.match.domain.JdMatchItemRelation;
import com.chenyue.cm.match.service.JdMatchItemService;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;


/**
 * @author chenyue-cm
 */
@Service(value = "JdMatchItemService")
public class JdMatchItemServiceImpl extends BaseServiceImpl<JdMatchItem> implements JdMatchItemService {

    private final JdMatchItemMapper jdMatchItemMapper;

    private final JdMatchItemRelationMapper jdMatchItemRelationMapper;

    public JdMatchItemServiceImpl(
            @Qualifier("jdMatchItemMapper") JdMatchItemMapper jdMatchItemMapper,
            @Qualifier("jdMatchItemRelationMapper") JdMatchItemRelationMapper jdMatchItemRelationMapper) {
        this.jdMatchItemMapper = jdMatchItemMapper;
        this.jdMatchItemRelationMapper = jdMatchItemRelationMapper;
    }

    @Override
    @Resource(name = "jdMatchItemMapper")
    public void setBaseMapper(LcBaseMapper<JdMatchItem, Serializable> baseMapper) {
        this.baseMapper = baseMapper;
    }

    @Override
    public List<JdMatchItem> matchItemListByTypeId(Integer typeId) {
        return lambdaQuery().eq(JdMatchItem::getTypeId, typeId).list();
    }

    @Override
    public List<JdMatchItemRelation> getMatchItemList(Integer matchId) {
        LambdaQueryWrapper<JdMatchItemRelation> wrapper = new LambdaQueryWrapper<>();
        if (matchId != null) {
            wrapper.eq(JdMatchItemRelation::getMatchId, matchId);
        }
        return jdMatchItemRelationMapper.selectList(wrapper);
    }
}
